# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=osgocean

pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn" "${MINGW_PACKAGE_PREFIX}-${_realname}-debug-svn")
_ver_base=1.0.1
pkgver=r258
pkgrel=1
pkgdesc="An ocean rendering nodekit for OpenSceneGraph (mingw-w64)"
arch=('any')
license=('LGPL')
url="https://code.google.com/p/osgocean/"
depends=("${MINGW_PACKAGE_PREFIX}-fftw" "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph")
makedepends=("subversion" 'unrar' "${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
options=(!strip staticlibs !buildflags)
source=("${_realname}"::"svn+http://osgocean.googlecode.com/svn/trunk/"
        "https://osgocean.googlecode.com/files/osgOcean-Resources-1.0.1.rar"
        "mingw-w64-cmake.patch"
        "osg-3.3.x.patch")
md5sums=('SKIP'
         'da273a112787e7911084d846082ff276'
         'ed27b3a9f14dbcc1bcb1ae0043cfe8ae'
         'ef0ec1d2947164acdb4931322ef79351')
noextract=( 'osgOcean-Resources-1.0.1.rar' )

pkgver() {
  cd "$srcdir/$_realname"
  local ver="$(svnversion)"
  printf "r%s" "${ver//[[:alpha:]]}"
}

prepare() {
  cd "$srcdir/${_realname}"/resources
  yes | unrar x "$startdir/osgOcean-Resources-1.0.1.rar"
  cd ../
  patch -p1 -i ${srcdir}/mingw-w64-cmake.patch
  patch -p1 -i ${srcdir}/osg-3.3.x.patch
}

build() {
  plain "No build step"
}

package_release() {
  provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
  conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
  
  [[ -d ${srcdir}/build-release ]] && rm -rf ${srcdir}/build-release
  mkdir -p ${srcdir}/build-release && cd ${srcdir}/build-release

  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DUSE_FFTW3=ON \
    -DUSE_FFTSS=OFF \
    ../${_realname}
  
  make
  make install
}

package_debug() {
  depends=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn=$pkgver" "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph-debug")
  provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-debug")
  conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-debug")
  
  [[ -d ${srcdir}/build-debug ]] && rm -rf ${srcdir}/build-debug
  mkdir -p ${srcdir}/build-debug && cd ${srcdir}/build-debug

  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Debug \
    -DUSE_FFTW3=ON \
    -DUSE_FFTSS=OFF \
    ../${_realname}
  
  make
  make install

  rm -rf ${pkgdir}${MINGW_PREFIX}/include
  rm -rf ${pkgdir}${MINGW_PREFIX}/bin/resources
  rm -rf ${pkgdir}${MINGW_PREFIX}/bin/*.exe
}

package_mingw-w64-i686-osgocean-svn() {
  package_release
}

package_mingw-w64-i686-osgocean-debug-svn() {
  package_debug
}

package_mingw-w64-x86_64-osgocean-svn() {
  package_release
}

package_mingw-w64-x86_64-osgocean-debug-svn() {
  package_debug
}

